/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using System.Collections.Generic;
using NetProtocol.POD;
using NetProtocol.Enum;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using IQIGame.Onigao.Framework;
using System.Threading.Tasks;
using System;

namespace NetProtocol.Server {
	/// <summary>
	/// 中心服投票模块
	/// module : centerEventVote
	/// </summary>
	public interface SNetCenterEventVote : INetServerModule {
		Dictionary<int, MessageHandler> INetServerModule.GetModuleFunction()
        {	
            return new()
            {
                { NetMessageId.centerEventVote_getVoteInfo, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.centerEventVote_getVoteInfo, "Recv->" + data.ToString());
#endif
		                GetVoteInfoRequest _data = (GetVoteInfoRequest)data;
						return CS_getVoteInfo(session, _data.eventId);
		            } 
            	},
            };
        }
        
        Dictionary<int, Func<IReceiveMessage>> INetServerModule.GetModuleRequest() 
        {
	        return new ()
	        {
	        	{NetMessageId.centerEventVote_getVoteInfo, ()=> new GetVoteInfoRequest()},
	        };
	    }
        
#region Server-side Interface
		/// <summary>
        /// 获取投票信息
        /// </summary>
	    protected GetVoteInfoResult CS_getVoteInfo(ISession session, int eventId);
#endregion
#region Client-side Interface
		/// <summary>
        /// 
        /// </summary>
        public GetVoteInfoResult SC_getVoteInfoResult(Task<GetVoteInfoResult> future){return new GetVoteInfoResult(future);}
        public GetVoteInfoResult SC_getVoteInfoResult(int code, CenterVoteDataPOD centerVoteDataPOD){return new GetVoteInfoResult(code, centerVoteDataPOD);}
        public GetVoteInfoResult SC_getVoteInfoResult(int code){return new GetVoteInfoResult(code);}
#endregion

#region Messages
	public class GetVoteInfoResult : MessageResult {
	    private CenterVoteDataPOD centerVoteDataPOD;
	    public GetVoteInfoResult(Task<GetVoteInfoResult> future): base(future) { }
		public GetVoteInfoResult(int code): base(code) { }
		public new GetVoteInfoResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal GetVoteInfoResult(int code, CenterVoteDataPOD centerVoteDataPOD){
	        this.code = code;
	        this.centerVoteDataPOD = centerVoteDataPOD;
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<GetVoteInfoResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.centerEventVote_getVoteInfoResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.centerEventVote_getVoteInfoResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_pod(centerVoteDataPOD);
			return si_p;
		}
		public override string ToString() {
    		return "CenterEventVote.SC_getVoteInfoResult { "
			+ "code="
			+ code
			+ ", centerVoteDataPOD="
			+ centerVoteDataPOD
			+" }";
		}
	}
	private class GetVoteInfoRequest : IReceiveMessage
    {
		internal int eventId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            eventId = _in.HasRemaining() ? _in.Read_int() : default;
		}
        public int GetMessageId() { return NetMessageId.centerEventVote_getVoteInfo; }
        public override string ToString()
        {
            return "CenterEventVote.getVoteInfo"+ ", eventId="+ eventId;
        }
    }
	}
#endregion
}